<?php

namespace ms\models\searchs;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use ms\models\SellWeekSelect;

/**
 * SearchSellWeekSelect represents the model behind the search form about `frontend\models\SellWeekSelect`.
 */
class SearchSellWeekSelect extends SellWeekSelect
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id', 'supplier_goods_id', 'base_id', 'img_id', 'store', 'site_id'], 'integer'],
            [['rom', 'zhishi', 'start_time', 'end_time'], 'safe'],
            [['te_price'], 'number'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = SellWeekSelect::find();

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        if (!($this->load($params) && $this->validate())) {
            return $dataProvider;
        }

        $query->andFilterWhere([
            'id' => $this->id,
            'supplier_goods_id' => $this->supplier_goods_id,
            'base_id' => $this->base_id,
            'img_id' => $this->img_id,
            'te_price' => $this->te_price,
            'store' => $this->store,
            'site_id' => $this->site_id,
        ]);

        $query->andFilterWhere(['like', 'rom', $this->rom])
            ->andFilterWhere(['like', 'zhishi', $this->zhishi])
            ->andFilterWhere(['like', 'start_time', $this->start_time])
            ->andFilterWhere(['like', 'end_time', $this->end_time]);

        return $dataProvider;
    }
}
